﻿@using Model.Admin;
@using Xproject.Util;
@{

    Layout = "~/Views/Shared/_JSlayout.cshtml";
    List<int> rolesId = (List<int>)ViewData["historyroles"];
    string Domain = CommonHelper.GetAppSettings("Domin");
}
@model List<AdminRole>
<div>
    <div class="  animated fadeInRight">
        <div class="row">
            <div class="form-group">
                <label class="col-sm-12 control-label">用户角色设置,用户可以有多个角色</label>

            </div>
            <div class="col-sm-12">

                <table class="table table-striped" id="roletables">
                    <thead>
                        <tr>
                            <th></th>
                            <th>角色名称</th>
                            <th>角色描述</th>
                            <th>操作</th>
                        </tr>
                    </thead>
                    <tbody>

                        @foreach (AdminRole ar in Model)
                        {
                            <tr>
                                <td>
                                    <img src="~/upload/img/user.png" />
                                </td>
                                <td>
                                    <a data-toggle="tab" href="#contact-1" class="client-link">@ar.RoleName</a>
                                </td>
                                <td> @ar.RoleDesc</td>

                                <td class="client-status">
                                    <input type="checkbox" class="checkbox" id="Enable" name="Enable" data-roleId="@ar.RoleId" @(rolesId.Contains(ar.RoleId) ? "checked" : "")>
                                </td>
                            </tr>
                        }

                    </tbody>
                </table>

            </div>
        </div>
        <div class="row">
            <div class="col-sm-4">
                <button class="btn btn-primary" onclick="UpdateUserRole()">提交</button>
            </div>
        </div>
    </div>
    <input type="hidden" id="ViewBaguserId" value="@ViewBag.userId" />
</div>
<script type="text/javascript">
    function UpdateUserRole() {

        var selectRoleId = new Array();
        $("#roletables").find("input").each(
            function (index, i) {
                var self = $(this);
                if (self.is(':checked')) {
                    selectRoleId.push(self.attr("data-roleId"));
                }
            }
        );

        if (selectRoleId.length <= 0) {
            layer.alert('没有为用户添加角色！请选择', { icon: 1, skin: 'layer-ext-moon', time: 2000 });
            return;
        }

        $.ajax({
            type: "POST",
            url: '@(Domain)/System/EditUserRoles',
            data: { productAttrs: list },
            cache: false,

            success: function (data) {
                layer.alert(data.Data, { icon: 1, skin: 'layer-ext-moon', time: 2000 });
            }
        });
    }
</script>

